<?php
/**
 * Leek - Zend Framework Components
 *
 * @category   Leek
 * @package    Leek_Application
 * @subpackage Resource
 * @author     Chris Jones <leeked@gmail.com>
 * @link       http://code.google.com/p/leek-zf-components/
 * @license    http://www.opensource.org/licenses/bsd-license.php New BSD License
 * @version    $Id: Multidb.php 59 2009-06-17 16:11:41Z leeked $
 */

/**
 * Resource for setting up multiple cache instances
 *
 * @uses       Zend_Application_Resource_ResourceAbstract
 * @category   Leek
 * @package    Leek_Application
 * @subpackage Resource
 * @author     Chris Jones <leeked@gmail.com>
 */
class Leek_Application_Resource_Multicache extends Zend_Application_Resource_ResourceAbstract
{
    /**
     * @uses Zend_Cache_Core
     * @var array
     */
    protected $_cacheObjects = array();

    /**
     * Adds a cache object to the stack
     *
     * @param string $cacheName
     * @param Zend_Cache_Core $cacheObject
     * @return Leek_Application_Resource_Multicache
     */
    public function addCacheObject($cacheName, $cacheObject)
    {
        if ($cacheObject instanceof Zend_Cache_Core) {
            $this->_cacheObjects[$cacheName] = $cacheObject;
        }

        return $this;
    }

    /**
     * Returns the cache object stack
     *
     * @return array
     */
    public function getCacheObjects()
    {
        return $this->_cacheObjects;
    }

    /**
     * Defined by Zend_Application_Resource_Resource
     *
     * @return array
     */
    public function init()
    {
        $options = $this->getOptions();

        // Loop through each cache name
        foreach ($options as $cacheName => $cacheOptions) {

            $resource = new Leek_Application_Resource_Cache($cacheOptions);
            $resource->init();
            $this->addCacheObject($cacheName, $resource->getCacheObject());

        }

        return $this->getCacheObjects();
    }
}
